package com.bo.entity;

import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;

import org.xmlpull.v1.XmlPullParser;

import android.content.res.XmlResourceParser;
import android.graphics.Bitmap;
import android.util.Xml;

import com.bo.util.LoadResourceProxy;


public class Company {
	
	private String id;
	private String name;
	private String address;
	private String image;
	private Bitmap bitmap;
	

	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getAddress() {
		return address;
	}
	public void setAddress(String address) {
		this.address = address;
	}
	public String getImage() {
		return image;
	}
	public void setImage(String image) {
		this.image = image;
	}
    public Bitmap getBitmap() {
		return bitmap;
	}
	public void setBitmap(Bitmap bitmap) {
		this.bitmap = bitmap;
	}
	
	
	
	public List<Company> createCompanyList(String search,int page,int offset) throws Exception{
		
    	List<Company> list=new ArrayList<Company>();
    	
		String xmlStr=LoadResourceProxy.getXMLStringPerPage(LoadResourceProxy.COMPANY_LIST,search,page,offset);
    	
		XmlPullParser xrp=Xml.newPullParser();

		if(xmlStr==null){
			
			throw new Exception("appear error");
		}
		
		StringReader reader=new StringReader(xmlStr);
		
		xrp.setInput(reader);
		
		  boolean isCompany=false;
		  Company cp=null;
			
		  while(xrp.getEventType()!=XmlResourceParser.END_DOCUMENT){
					
			 if(xrp.getEventType()==XmlResourceParser.START_TAG){
						
			       String tagName=xrp.getName();
			       
				   if(tagName.equalsIgnoreCase("Company")){
							
					   isCompany=true;
					   cp=new Company();
					       
				   }else if(tagName.equalsIgnoreCase("id")&&isCompany){
					   
					   cp.setId(xrp.nextText());
					   
				   }else if(tagName.equalsIgnoreCase("name")&&isCompany){
					   	
					   cp.setName(xrp.nextText());
					
				   }else if(tagName.equalsIgnoreCase("address")&&isCompany){
					   	
					   cp.setAddress(xrp.nextText());
				   
				   }else if(tagName.equalsIgnoreCase("image")&&isCompany){
					   
					   cp.setImage(xrp.nextText());
				   }
						
			   }else if(xrp.getEventType()==XmlResourceParser.END_TAG){
				   
				   String tagName=xrp.getName();
				   
				   if(tagName.equalsIgnoreCase("Company")){
						
					   isCompany=false;    
					   
					   list.add(cp);
				   }
			   }
					
				xrp.next();
			}
		
		return list;	
    }

}
